const button = document.getElementById("enter") as (HTMLButtonElement | null);
const login = document.getElementById("login") as (HTMLInputElement | null);
const password = document.getElementById("password") as (HTMLInputElement | null);
const erortext = document.getElementById("error-text") as (HTMLSpanElement | null);
if (button !== null && login !== null && password !== null) {
    button.onclick = async () => {
        if (login.value.length > 0 && password.value.length > 0) {
            let r = await (await fetch("/auth", {
                method: "post",
                headers: { "Content-Type": "application/json" },
                body: JSON.stringify({ login: login.value, password: password.value }),
            })).json() as { res: "bad", text: string } | {res: "ok"};
            if(r.res == "bad" && erortext !== null){
                erortext.innerText = r.text;
            }else{
                window.location.reload();
            }
        } else {
            if (erortext !== null) {
                erortext.innerText = "Поле логин и пароль не должны быть пустыми";
            }
        }
    }
}